App.controller('sidebarController', function($scope, $http, $state) {
    
	$http.get('js/common/menu.json?v=' + new Date().getTime()).success(function(data){
		
		$scope.menus = data;
	});
	
	$scope.getMenuItemPropClasses = function(item) {
		
		var defaultClass = item.submenu ? 'dropdown' : '';
		
		return isActive(item) ?  defaultClass + ' active' : defaultClass;
    };
	
    var isActive = function(item) {

      if(!item) return;

      if( !item.path || item.path == '') {
    	  var foundActive = false;
    	  angular.forEach(item.submenu, function(value, key) {
	          if(isActive(value)) {
	        	  foundActive = true;
	          }
	      });
    	  return foundActive;
      }
      else {
    	  
    	  var currentPath = $state.current.name;
    	  var paths = currentPath.split('.');
    	  if(paths.length > 2){
    		  
    		  var mainPath = paths[0] + '.' + paths[1];
    		  if(item.path.indexOf(mainPath) > -1){
    			  
    			  return true;
    		  }
    	  }
    	  
    	  return $state.is(item.path) || $state.includes(item.path);
      }
    };
});